package com.example.ovulationperiodtracker.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.databinding.DialogConfirBinding;
import com.example.ovulationperiodtracker.databinding.DialogInputBinding;


public class ComfirDialog extends Dialog {

    private OnClickYesNoListener onClickYesNoListener;
    private String title;
    private Context context;

    public ComfirDialog(@NonNull Context context, String title) {
        super(context);
        this.title = title;
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DialogConfirBinding binding = DialogConfirBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();

        // 获取屏幕宽度
        int screenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
        // 设置 Dialog 宽度为屏幕宽度的 80%
        layoutParams.width = (int) (screenWidth * 0.8);
        window.setAttributes(layoutParams);
        window.setBackgroundDrawableResource(R.drawable.bg_dialog_ys);

        setCanceledOnTouchOutside(false);

        binding.title.setText(title);


        binding.tvNo.setOnClickListener(v -> {
//            if (onClickYesNoListener != null) {
//                onClickYesNoListener.onClickNo();
//            }
            dismiss();
        });

        binding.tvYes.setOnClickListener(v -> {
            if (onClickYesNoListener != null) {
                onClickYesNoListener.onClickYes();
            }
            dismiss();
        });

    }

    public ComfirDialog setOnClickYesNoListener(OnClickYesNoListener onClickYesNoListener) {
        this.onClickYesNoListener = onClickYesNoListener;
        return this;
    }

    public interface OnClickYesNoListener {
        void onClickYes();

        // void onClickNo();
    }
}